import redis,threading
import time
ip = '192.168.16.1'
connre = redis.Redis(ip)
r_x = 0
r_y = 0
scale = 1
last_time = 0

def do_one():
    global r_x,r_y
    t1 = time.time()
    x = connre.blpop('dxdy')[1]
    block_time = time.time()-t1
    if block_time>0.8:
        print('clear',time.time())
        r_x = 0
        r_y = 0
    x = str(x)
    x = x.replace("'",'').replace('b','')
    dx,dy = str(x).split('#')
    dx = int(dx)
    dy = int(dy)

    print(x)
    while True:
        a = connre.lpop('dxdy')
        if not a:
            break
        a = str(a)
        a = a.replace("'",'').replace('b','')
        print(a)
        dx2,dy2 = str(a).split('#')
        dx2 = int(dx2)
        dy2 = int(dy2)
        dx += dx2
        dy += dy2
    r_x += dx*scale
    r_y += dy*scale
    dx = round(r_x)
    dy = round(r_y)

    r_x = r_x-dx
    r_y = r_y-dy
    mouse.Controller().move(dx,dy)

from pynput import keyboard,mouse
while True:
    do_one()
    print('do_one')